<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>费用管理</title>
<base href="<%=basePath%>">
<script type="text/javascript"
	src="plugins/websocketInstantMsg/ext4/ext-all-debug.js"></script>
<script type="text/javascript" src="static/js/jquery-1.7.2.js"></script>
<script type="text/javascript"
	src="plugins/websocketInstantMsg/ext4/locale/ext-lang-zh_CN.js"></script>
<link rel="stylesheet"
	href="plugins/websocketInstantMsg/ext4/resources/css/ext-all.css" />
</head>

<body>
<div id="div1" style="height:45px"></div>
<div id="aa"></div>
</body>
<script type="text/javascript">
Ext.onReady(function () {
	Ext.QuickTips.init();
    var store = Ext.create('Ext.data.Store', {
        fields:  ["ID","FAST_SEARCH_CODE","FEE_NAME","ENABLE","DEPARTMENT","IS_ACCEPT_AMEND","IS_SPECIAL_FEE","REMARK",
                  "OPEN_TICKET_FEE_NAME","OPEN_TICKET_TAX_RATE","FEE_CODE"],
        pageSize: 20,  //页容量5条数据
        //是否在服务端排序 （true的话，在客户端就不能排序）
        remoteSort: false,
        remoteFilter: true,
        proxy: {
            type: 'ajax',
            url: '<%=basePath%>cost/list',
            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
                type: 'json', //返回数据类型为json格式
                root: 'rows',  //数据
                totalProperty: 'total' //数据总条数
            }
        },
        sorters: [{
			property: 'ordeId',
			direction: 'desc'
		}],
        autoLoad: true  //即时加载数据
    });
    
   
//新建的列表
    var grid = Ext.create('Ext.grid.Panel', {
    renderTo: "aa",
    id:'grid',
    store: store,
    height: 400,
    width:"100%",
    
    selModel:Ext.create('Ext.selection.CheckboxModel',{mode:"SIMPLE"}),
    //selModel: { selType: 'checkboxmodel' },   //选择框
    columns: [                    
                  { text: 'ID', dataIndex: 'ID',  maxWidth: 700 ,hidden:true,},
                  { text: '快速检索码', dataIndex: 'FAST_SEARCH_CODE', align: 'left', minWidth: 80,  },
                  { text: '费用名称', dataIndex: 'FEE_NAME',  maxWidth: 140, },   
                  { text: '费用代码', dataIndex: 'FEE_CODE',  maxWidth: 140, },   
                  { text: '开票费用名称', dataIndex: 'OPEN_TICKET_FEE_NAME', maxWidth: 120, align: 'left', }, 
                  { text: '部门', dataIndex: 'DEPARTMENT', maxWidth: 120, align: 'left', },
                  { text: '税率', dataIndex: 'OPEN_TICKET_TAX_RATE', maxWidth: 120, align: 'left', }, 
                  { text: '是否可用', dataIndex: 'ENABLE', maxWidth: 120, align: 'left', },                  
                  { text: '是否接受后补', dataIndex: 'IS_ACCEPT_AMEND', maxWidth: 700, align: 'left', }, 
                  { text: '是否特殊费用', dataIndex: 'IS_SPECIAL_FEE', maxWidth: 700, align: 'left', }, 
                  { text: '备注', dataIndex: 'REMARK', maxWidth: 700, align: 'left', }, 
                 
                 
               ],
    bbar: [{
        xtype: 'pagingtoolbar',
        store: store,
        displayMsg: '显示 {0} - {1} 条，共计 {2} 条',
        emptyMsg: "没有数据",
        beforePageText: "当前页",
        afterPageText: "共{0}页",
        displayInfo: true                 
    }],
  
     tbar:[
     {text:'新增',iconCls:'a_add',handler : showAlert},"-",
     {text:'修改',iconCls:'a_edit2',handler: editAlert,},
     {text:'删除',iconCls:'a_edit2',handler: delteAlert,},
  ], 
     
});
 //新增   
function showAlert (){
win.show();
}


//修改
function editAlert (){
	
	var records = grid.getSelectionModel().getSelection();//获取选中一行的值

   	 if(records.length==0){
     			Ext.Msg.alert("提示","请选择需要编辑的记录");return;
     		}
     		if(records.length>1){
     			Ext.Msg.alert("提示","只能编辑一条记录");return;
     		}
     		
     		var ID = records[0].data.ID;
            Ext.getCmp("ID").setValue(ID);
     		
			
     		
     		var FAST_SEARCH_CODE = records[0].data.FAST_SEARCH_CODE;
     		Ext.getCmp("FAST_SEARCH_CODE").setValue(FAST_SEARCH_CODE);
     		
     		var FEE_NAME = records[0].data.FEE_NAME;
     		Ext.getCmp("FEE_NAME").setValue(FEE_NAME);
     		
     		var ENABLE = records[0].data.ENABLE;
     		Ext.getCmp("ENABLE").setValue(ENABLE);
     		 
     		var DEPARTMENT = records[0].data.DEPARTMENT;
     		Ext.getCmp("DEPARTMENT").setValue(DEPARTMENT);
     		
     		var IS_ACCEPT_AMEND = records[0].data.IS_ACCEPT_AMEND;
     		Ext.getCmp("IS_ACCEPT_AMEND").setValue(IS_ACCEPT_AMEND);
     		
     		
     		
     		var IS_SPECIAL_FEE = records[0].data.IS_SPECIAL_FEE;
     		Ext.getCmp("IS_SPECIAL_FEE").setValue(IS_SPECIAL_FEE);
     		
     		var REMARK = records[0].data.REMARK;
     		Ext.getCmp("REMARK").setValue(REMARK);
     		
     		var OPEN_TICKET_FEE_NAME = records[0].data.OPEN_TICKET_FEE_NAME;
     		Ext.getCmp("OPEN_TICKET_FEE_NAME").setValue(OPEN_TICKET_FEE_NAME);
     		
     		var FEE_CODE = records[0].data.FEE_CODE;
     		Ext.getCmp("FEE_CODE").setValue(FEE_CODE);
     		
     		
	       win.show();

	}
	//删除
	function  delteAlert(){
		var records = grid.getSelectionModel().getSelection();
 		if(records.length==0){
 				Ext.Msg.alert("提示","请选中需要删除的记录");return;
 			}
 			var arr = [];
 			Ext.each(records,function(item){
 				obj = {
 						id:item.data.ID
 						
 				};
 				arr.push(obj);
 				
 			});
 			var array = JSON.stringify(arr);
 			Ext.Ajax.request({
 						url:  '<%=basePath%>cost/deleteU',
						params:{
							array:array		
						},
						timeout:5000,
						success:function(response){
							 Ext.MessageBox.alert("删除","删除成功");
							 var store = Ext.getCmp('grid').getStore();
							 store.reload();
						},
						
					});
 	}



	
	//保存按钮
	var save = new Ext.Button({
     	text: '保存',
     	 handler: function(){ 
     		var ID = Ext.getCmp('ID').getValue();   		
			var FAST_SEARCH_CODE = Ext.getCmp('FAST_SEARCH_CODE').getValue(); //快速检索码
     		//alert(FAST_SEARCH_CODE)
     		var FEE_NAME = Ext.getCmp('FEE_NAME').getValue();//费用名称
     		//alert(FEE_NAME)
			var ENABLE = Ext.getCmp('ENABLE').getValue();//是否可用
     		//alert(ENABLE)
     		var DEPARTMENT = Ext.getCmp('DEPARTMENT').getValue();//部门
     		//alert(DEPARTMENT)
     		var IS_ACCEPT_AMEND = Ext.getCmp('IS_ACCEPT_AMEND').getValue();//是否接受后补
     		//alert(IS_ACCEPT_AMEND)
     		var IS_SPECIAL_FEE = Ext.getCmp('IS_SPECIAL_FEE').getValue();//是否特殊费用
     		//alert(IS_SPECIAL_FEE)
     		
     		var REMARK = Ext.getCmp('REMARK').getValue();//备注
     		//alert(REMARK)
     	
     		var OPEN_TICKET_FEE_NAME = Ext.getCmp('OPEN_TICKET_FEE_NAME').getRawValue();//开票费用名称
     		//alert(OPEN_TICKET_FEE_NAME)
     		var OPEN_TICKET_TAX_RATE = Ext.getCmp('OPEN_TICKET_TAX_RATE').getValue();//开票税率
     		//alert(OPEN_TICKET_TAX_RATE)
     		var OPEN_TICKET_FEE_NAME_ID = Ext.getCmp('id').getValue();//开票费用id
     		//alert(OPEN_TICKET_FEE_NAME_ID)
     		var FEE_CODE = Ext.getCmp('FEE_CODE').getValue();//费用CODE
			var store = Ext.getCmp('grid').getStore();
	  		 Ext.Ajax.request({
     			url: '<%=basePath%>cost/addcost',
					params : {
						ID : ID,
						FAST_SEARCH_CODE : FAST_SEARCH_CODE,
						FEE_NAME : FEE_NAME,
						ENABLE : ENABLE,
						DEPARTMENT : DEPARTMENT,
						IS_ACCEPT_AMEND : IS_ACCEPT_AMEND,
						IS_SPECIAL_FEE : IS_SPECIAL_FEE,
						REMARK : REMARK,
						OPEN_TICKET_FEE_NAME  : OPEN_TICKET_FEE_NAME,
						OPEN_TICKET_TAX_RATE : OPEN_TICKET_TAX_RATE,
						OPEN_TICKET_FEE_NAME_ID : OPEN_TICKET_FEE_NAME_ID,
						FEE_CODE : FEE_CODE,
					},
					method : 'POST',
					success : function() {
						Ext.MessageBox.alert("保存成功", "保存成功");
                         
						win.close();
						store.load();
					},
				});

			}

		});
	//重置按钮
		var reset = new Ext.Button({
			text : '重置',
			listeners : {
				'click' : function() {
					Ext.getCmp('add').form.reset();
				
				}
			}
		}

		);
	//取消按钮
		var cancel = new Ext.Button({
			text : '取消',
			listeners : {
				'click' : function() {
					win.close();
				}
			}
		}

		);
	//税率
		var shuilv = Ext.create('Ext.data.Store', {
			fields: ['id', 'name'],
			data : [
                {"id":"", "name":"全部"},
				{"id":"0", "name":"0%"},
				{"id":"1", "name":"3%"},
				{"id":"2", "name":"3%"},
				{"id":"3", "name":"6%"},
				{"id":"4", "name":"11%"},
				{"id":"5", "name":"17%"},
				
			
			]
		});
	//开票费用下拉
		 var feiyong = Ext.create('Ext.data.Store', {
		        fields: ["id","fee_name","tax_rate"],
		        remoteSort: false,
		        remoteFilter: true,
		        proxy: {
		            type: 'ajax',
		            url: '<%=basePath%>cost/feiyong',
		            reader: {   //这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
		                type: 'json', //返回数据类型为json格式
		                root: 'rows2',  //数据
		                totalProperty: 'tota2' //数据总条数
		            }
		        },
		        sorters: [{
					property: 'ordeId',
					direction: 'desc'
				}],
		        autoLoad: true  //即时加载数据
		    });
	     //托单状态的下拉
		var enableStore = Ext.create('Ext.data.Store', {
			fields: ['id', 'name'],
			data : [
                {"id":"", "name":"全部"},
				{"id":"0", "name":"否"},
				{"id":"1", "name":"是"},
			
			]
		});
		  //是否接受后补的下拉
		var enableStore1 = Ext.create('Ext.data.Store', {
			fields: ['id', 'name'],
			data : [
                {"id":"", "name":"全部"},
				{"id":"0", "name":"否"},
				{"id":"1", "name":"是"},
			
			]
		});
		  //是否特殊费用下拉
		var enableStore2 = Ext.create('Ext.data.Store', {
			fields: ['id', 'name'],
			data : [
                {"id":"", "name":"全部"},
				{"id":"0", "name":"否"},
				{"id":"1", "name":"是"},
			
			]
		});
	//新增一个form表单
		var add = Ext.create("Ext.form.Panel", {
             id:'add',
			frame : true,
			width : 456,
			height : 600,

			defaults : {
				anchor : '100%',
				labelWidth : 50,
				labelAlign : "right"
			},
			items : [ {
				id : 'ID',
				hidden : true,
				hideLabel : true,
				xtype : 'textfield',
				fieldLabel : 'ID',
				name : 'ID'
			}, {
				id : 'FAST_SEARCH_CODE',
				fieldLabel : '检索码',
				name : 'FAST_SEARCH_CODE',
				xtype : 'textfield',
				emptyText:'请输入检索码',
				
			}, 
             {
				
				id:'FEE_NAME',				
				fieldLabel : '费用名称',
				name : 'FEE_NAME',
				xtype : 'textfield',
				emptyText:'请输入费用名称',
				

			},
			{
				id:'FEE_CODE',				
				fieldLabel : '费用代码',
				name : 'FEE_CODE',
				xtype : 'textfield',
				emptyText:'请输入费用代码',
				
				
			},
            {
				
				id:'DEPARTMENT',				
				fieldLabel : '部门',
				name : 'DEPARTMENT',
				xtype : 'textfield',
				emptyText:'请输入部门',
				

			},
             {
				id:'REMARK',				
				fieldLabel : '备注',
				name : 'REMARK',
				xtype : 'textfield',
				emptyText:'请输入备注',
			},
			{   
				id : 'OPEN_TICKET_FEE_NAME',
				fieldLabel : '开票费用名称',
				name : 'OPEN_TICKET_FEE_NAME',
				xtype : 'combobox',
				emptyText:'请选择',
				store : feiyong,
				valueField: 'tax_rate',
				displayField:'fee_name',
				editable: false,
				listeners : { //监听该下拉列表的选择事件
					select : function(combo, record, index) {
			               var fename = Ext.getCmp('OPEN_TICKET_FEE_NAME').getValue();
			            Ext.getCmp('OPEN_TICKET_TAX_RATE').setValue(fename);			          
			            var a=  combo.findRecordByValue(combo.getValue()).get('id') 
			            //alert(a)
						       Ext.getCmp('id').setValue(a);	
		
			            }
			        }
			},
			 {
				id:'OPEN_TICKET_TAX_RATE',				
				fieldLabel : '开票税率',
				name : 'OPEN_TICKET_TAX_RATE',
				xtype : 'textfield',
				emptyText:'税率',
				hidden:true
				
			},
			{
				id:'id',				
				fieldLabel : 'id',
				name : 'id',
				xtype : 'textfield',
				emptyText:'id',
				hidden:true
			},
			{   
				id : 'ENABLE',
				fieldLabel : '是否可用',
				name : 'ENABLE',
				xtype : 'combobox',
				emptyText:'请选择',
				store : enableStore,
				valueField: 'id',
				displayField:'name',
				editable: false,
			},
			{
				id : 'IS_ACCEPT_AMEND',
				fieldLabel : '是否接受后补',
				name : 'IS_ACCEPT_AMEND',
				xtype : 'combobox',
				emptyText:'请选择',
				store : enableStore1,
				valueField: 'id',
				displayField:'name',
				editable: false,
			},
			{
				id : 'IS_SPECIAL_FEE',
				fieldLabel : '是否特殊费用',
				name : 'IS_SPECIAL_FEE',
				xtype : 'combobox',
				emptyText:'请选择',
				store : enableStore2,
				valueField: 'id',
				displayField:'name',
				editable: false,
			},
			
			
			],
			
		});
        //新建一个窗口，把form表单放进去
		var win = Ext.create("Ext.window.Window", {
			title : '新增',
			width : 460,
			height : 400,  
			resizable : true,
			modal : true,
			closable : true,
			maximizable : true,
			minimizable : true,
			closeAction :'hide',//点击第二次
			buttons : [ save, reset, cancel ],
		
			items : [ add ],
		});
           
        //新建查询列表
		var c1 = Ext.create('Ext.container.Container', {
			layout : 'column',
			
			defaults : {
				labelAlign : 'left',
				labelWidth : 60
			},
			items : [
					{
						xtype : 'textfield',
						name : 'FEE_NAME',
						id : 'a',
						columnWidth : 1 / 6,
						padding : '5px',
						fieldLabel : '费用名称',
						emptyText:'请输入费用名称',
					},
					{
						xtype : 'textfield',
						name : 'FAST_SEARCH_CODE',
						id : 'b',
						columnWidth : 1 / 6,
						padding : '5px',
						fieldLabel : '检索码',
						emptyText:'请输入快速检索码',
					},
					
					
					{
						xtype : "button",
						padding : '5px',
						text : '查询',
						handler : function() {
					var FAST_SEARCH_CODE = Ext.getCmp('a').getValue();//报关方式
					//alert(FAST_SEARCH_CODE)
				
					var FEE_NAME = Ext.getCmp('b').getValue();//快速检索码
					//alert(FEE_NAME)
					
					
					
				
					var store = Ext.getCmp('grid').getStore();
					store.on('beforeload', function(store, options) {
						var new_params = {
								FEE_NAME : FEE_NAME, //费用名称
								FAST_SEARCH_CODE : FAST_SEARCH_CODE, //快速检索码
							
						};
						Ext.apply(store.proxy.extraParams, new_params);
					});
					store.load();
				}
			},{
				xtype : "button",
				padding : '6px',
				text : '清空信息',
				listeners : {
					'click' : function() {
						
						Ext.getCmp('re').form.reset();
					
					}
				}
				
			}
					
					]

		});
           //把查询的列表放进form中
		var form = Ext.create('Ext.form.Panel', {
			renderTo : 'div1',
			frame : true,
			id:'re',
			items : [ c1 ],
// 		 buttons: [{
// 		         text: '查询',
// 		         handler: function() {
// 		             var form=this.up('form');
// 		             var id=form.down('textfield[name=id]').value;
// 		             var uname=form.down('textfield[name=useName]').value;
// 		             if(!id){
// 		             alert('编号不能为空！');
// 		             return;
// 		             }
// 		             if(!uname){
// 		             alert('名称不能为空！');
// 		             return;
// 		             }
// 		            Ext.MessageBox.alert('提示框','提交成功，正在保存数据，请稍后！');
// 		         }
// 		   }]
 		});

	});



</script>
</html>